<?php

declare(strict_types=1);

namespace App\Admin\Controller\System\DataCenter;

use App\Admin\Annotation\Auth;
use App\Admin\Request\System\Message\SendPrivateMessageRequest;
use App\Admin\Service\System\SystemQueueMessageService;
use DI\Attribute\Inject;
use Newbie\Annotation\Attributes\Route\Controller;
use Newbie\Annotation\Attributes\Route\DeleteMapping;
use Newbie\Annotation\Attributes\Route\GetMapping;
use Newbie\Annotation\Attributes\Route\PostMapping;
use Newbie\Annotation\Attributes\Route\PutMapping;
use Newbie\NewbieController;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use support\Request;
use support\Response;

/**
 * 信息管理控制器
 * Class MessageController
 */
#[Controller(prefix: "system/queueMessage"), Auth]
class QueueMessageController extends NewbieController {
    #[Inject]
    protected SystemQueueMessageService $service;

    /**
     * 接收消息列表
     * @param Request $request
     * @return Response
     */
    #[GetMapping("receiveList")]
    public function receiveList (Request $request): Response {
        return $this->success($this->service->getReceiveMessage($request->all()));
    }

    /**
     * 已发送消息列表
     * @return Response
     */
    #[GetMapping("sendList")]
    public function sendList (): Response {
        return $this->success($this->service->getSendMessage($this->request->all()));
    }

    /**
     * 发私信
     * @param SendPrivateMessageRequest $request
     * @return Response
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws \Throwable
     */
    #[PostMapping("sendPrivateMessage")]
    public function sendPrivateMessage (SendPrivateMessageRequest $request): Response {
        return $this->service->sendPrivateMessage($request->validated()) ? $this->success() : $this->error();
    }

    /**
     * 获取接收人列表
     * @param Request $request
     * @return Response
     */
    #[GetMapping("getReceiveUser")]
    public function getReceiveUser (Request $request): Response {
        return $this->success(
            $this->service->getReceiveUserList(
                (int)$request->input('id', 0),
                $request->all()
            )
        );
    }

    /**
     * 单个或批量删除数据到回收站
     * @param String $ids
     * @return Response
     */
    #[DeleteMapping("deletes/{ids}")]
    public function deletes (string $ids): Response {
        return $this->service->delete($ids) ? $this->success() : $this->error();
    }

    /**
     * 更新状态到已读
     * @param String $ids
     * @return Response
     */
    #[PutMapping("updateReadStatus/{ids}")]
    public function updateReadStatus (string $ids): Response {
        return $this->service->updateDataStatus($ids) ? $this->success() : $this->error();
    }
}
